Tangible Software Solutions
Java to C++ Converter Help
Contents
- Folder Conversion
- File & Snippet Conversion
- Command Line Conversion
- Code Formatting Options
- Modern C++ Options
- Header File Options
- Additional Stack Allocation Types
- Additions & Omissions
- Conversion Message Options
- Custom String Replacements
- Type & Member Replacements
- Diagnostic Options
- File Encoding Options
- Naming Conventions
- Omit Types from Conversion
- Miscellaneous Options
Folder Conversion
The Folder Converter tab allows you to convert all Java code
within a folder. Once the files are converted, you can then view Java to C++ Converter
comments, compare converted code files to original code files, and view the converted
code folder.
The Conversion History listview displays previously converted sources and allows you to
view remaining Java to C++ Converter comments and view the converted code folder.
Note that due to the lack of similarity between Java and C++ project types and
project files, Java to C++ Converter does not generate C++ project files. You need
to assemble the resulting header and .cpp files generated by Java to C++ Converter.
The default output of the conversion is the traditional .h and .cpp file separation,
but you can select the option of outputting to just header files (with combined declaration
and implementation details).
File & Snippet Conversion
The File & Snippet Converter tab allows you to convert
Java code snippets or files. From the left side textbox, you can type
or paste code snippets, insert files, or view Java to C++ Converter sample snippets.
Once a file or snippet is converted, you can select and copy the results, save the
results to a file, or search the results.
Command Line Conversion
Java to C++ Converter can be launched from the command line
with two or three parameters plus an optional last parameter indicating the location of
a conversion options file. If you specify folders, the first parameter is the Java source
code folder that you wish to convert, and the second parameter is the folder that the
converted C++ files will be written to. If you specify files, the first parameter is
the source code file that you wish to convert, and the second parameter is the name of
the converted C++ header file. If the optional last parameter indicating the location of a conversion options file is included,
then that file is imported before the conversion starts. A conversion options file
has the extension '.opt' and is produced by exporting existing options to an xml file from the converter.
e.g. (folder conversion),
"Java to C++ Converter" "C:\Java Source Code\Sample Source Folder" "C:\C++ Projects\Sample Target Folder"
e.g. (file conversion),
"Java to C++ Converter" "C:\Java Source Files\testfile.java" "C:\C++ Converted Files\testfile.h"
e.g. (folder conversion with a conversion options file specified),
"Java to C++ Converter" "C:\Java Source Code\Sample Source Folder" "C:\C++ Projects\Sample Target Folder" "C:\Options\Java to C++ Converter.opt"
Once the command line conversion is complete, Java to C++ Converter will shut down.
Note that Java to C++ Converter must be in double quotes since the executable name
contains spaces.
- Braces: You can choose whether to place opening
braces on the next line after the construct header (default) or at the end of the same line.
You can choose whether to have braces vertically aligned with the construct (default) or
indented. Loops and if or else blocks with a single statement are converted by default
with enclosing braces. If you prefer to exclude braces for these cases then check
the preference to remove braces for single statement loops and if/else blocks.
- Indentation: You can choose whether the converted code uses
tabs or spaces for the leading white space. If you choose tabs for leading white space, then
leading spaces in the original code of the length that you specify are replaced by tabs. If you
choose spaces for leading white space, then tabs in the original code are replaced by spaces
of the length that you specify.
- Spacing: You can choose the degree to which
Java to C++ Converter inserts spaces in the converted code. By default, binary operators
are padded with spaces and control structures have a space inserted after the keyword,
but you can switch off this behavior or insert spaces in other situations.
- Line Endings: By default, the converter separates lines
of code in the output by the Windows line ending \r\n. If you want the non-Windows line
ending \n, then you can choose this option.
- Pointers: You can select
to place the pointer symbol either "immediately before name"
or "immediately after type".
- Control Statements: If you
select this option, the converter will break apart control structure statements
(if and while statements) by the main conditions. See the output in the
textbox to see the effect of this option.
- Method Declarations: If you select this
option, the converter will break apart method declarations by the method parameters. See the
output in the textbox to see the effect of this option.
- Method Calls: If you select this
option, the converter will break apart method calls by the method call arguments. See the
output in the textbox to see the effect of this option.
- String Literal Concatenation: If you select this
option, the converter will break apart multiple string literal concatenations to separate
lines. See the output in the textbox to see the effect of this option.
Modern C++ Options
- Convert to fixed-width integer types: Select this
option if you want to convert to fixed-width integer types defined in the cstdint header.
- Convert String.format to C++20 std::format: Select this
option if you are targeting C++20 and wish to use std::format.
- Allow nested namespaces in single namespace statements:
C++17 allows nested namespaces in a single namespace statement. Select this
option if you are targeting C++17.
- Allow simple string literal concatenation:
C++14 allows simple string literal concatenation without the need for any casting.
- Convert java.lang.Object to std::any: Select this
option if you would like the std::any type (C++17) to be used as a replacement
for java.lang.Object.
- Convert to 'smart' pointers via C++11 std::shared_ptr:
You have the option of converting to std::shared_ptr smart pointers.
This option doesn't apply to arrays - if you want a similar approach to
arrays, use the 'convert arrays to std::vector' option.
- Convert 'synchronized' blocks to std::scoped_lock: By default,
synchronized blocks are converted to std::scoped_lock (C++17).
- Convert java.util.Optional to std::optional: By default,
the converter translates the java.util.Optional type to std::optional (C++17).
- Convert base class generic constraints using C++20 concepts:
C++20 provides a syntax and library for template constraints. Select this option if you are targeting C++20.
- Convert wrapper types to std::optional: By default,
the converter translates the nullable Java wrapper types (e.g., java.lang.Integer)
to std::optional (C++17).
- Header file guards: Java to C++ Converter includes
#pragma once statements in header files by default, but if you need to use the
traditional header guard approach (using #ifndef / #define), then select this option.
The capitalized header name is used plus any prefix or suffix that you enter.
- Keep template type implementations within header files:
By default, Java to C++ Converter keeps template type implementations within header files
regardless of the output option you select. This is the most common approach to template types,
however you can choose to have the implementations in the .cpp file if you wish.
- Keep template method implementations within header files:
By default, Java to C++ Converter keeps template method implementations within header files
regardless of the output option you select. This is the most common approach to template methods,
however you can choose to have the implementations in the .cpp file if you wish.
- Add #include statements for unknown types: By default,
Java to C++ Converter adds #include statements corresponding to the types referenced in the
code which are also defined in the code being converted. However, if you select this option,
the converter will add #include statements for types not defined in the code being converted.
- Add #include "stdafx.h": Select this option if you want
the converted code to include stdafx.h for Microsoft-specific implementations.
Additional Stack Allocation Types
Java to C++ Converter handles conversion of type references and
method parameters based on whether the type is a Java class, enum, or interface.
However, if you want to force certain types to be allocated on the stack, you can
specify that here. This forces the converter to treat
the specified type as if it were originally a value type. 'Variables are reference variables,
if possible' forces the converter to declare variables of the type as references if they're
assigned to another instance. 'Parameters are reference parameters' forces the converter
to always convert to reference parameters for specified type.
'Parameters are const' forces the converter to always add the const modifier
to parameters of the specified type.
Additions & Omissions
- Add to the top of all converted header files: If you add
text for this option, that text will be added to the top of every converted header file.
This option does not apply to code snippet conversions.
- Add to the top of all converted .cpp files: If you add
text for this option, that text will be added to the top of every converted .cpp file.
This option does not apply to code snippet conversions.
- Omit code from conversion wrapped in the following xml tag comments:
If you would like to have code omitted from the conversion output instead of converted,
then enter a tag that you will use to identify this code to Java to C++ Converter.
For example, if you enter the tag "code", then conversion of the code
inside of a <code>...</code> comment pair will be omitted
by the converter.
- Comment code wrapped in the following xml tag comments:
If you would like to have Java code left unconverted and commented out in the conversion
output, then enter a tag that you will use to identify this code to Java to C++ Converter.
For example, if you enter the tag "code", then the code inside of
a <code>...</code> comment pair will be commented out by the converter.
- Uncomment code in comments wrapped in the following xml tag - with conversion:
If you would like to have Java code within comments uncommented and converted,
then enter a tag that you will use to identify this code to Java to C++ Converter.
For example, if you enter the tag "code", then the text inside
of <code>...</code> blocks within comments will be converted by
Java to C++ Converter and uncommented. Note that this code must fit into
the context of the surrounding code since it will be uncommented in the output.
- Uncomment code in comments wrapped in the following xml tag - without conversion:
If you would like to have Java code within comments uncommented without conversion,
then enter a tag that you will use to identify this code to Java to C++ Converter.
For example, if you enter the tag "code", then the text inside
of <code>...</code> blocks within comments will be uncommented
without conversion by Java to C++ Converter. Note that this code must fit
into the context of the surrounding code since it will be uncommented in the output.
Conversion Message Options
On this options dialog, you can customize the comment prefixes
that the converter uses for messages and also toggle the messages that Java to C++ Converter
displays on or off.
You can easily set all or none to display via the 'Select All' and 'Select None' buttons.
Custom String Replacements
Java to C++ Converter allows you to specify your own
custom replacements in the converted C++ code. This can be useful for customizing
code according to style preferences that may be different in C++ than in Java.
It's also useful for cases where a Java method without a good C++ equivalent
will be replaced by your own custom method to be called from the converted code.
For each replacement string you can specify the regex option, when to perform the replacement
(pre or post conversion), whether or not to match case, whether to match whole words only,
and whether comments or string literals should be modified. The whole words and string literals
options do not apply if the regex option is selected.
To span mulitple lines, either paste directly into the 'Find' and 'Replacement'
textboxes, or use the escaped characters: \r\n\t.
The "Active" checkbox can be unchecked if you wish to temporarily bypass the replacement.
Replacements are made in the order that they appear on the options dialog. For example,
the second replacement is made to each line of code after the first replacement has already
been made. To change the order of replacements, use the 'Up' and 'Down' buttons.
For an example of the regex option, you could do a custom replacement of "Foo(x)" with "Bar(x)",
where "x" is any argument, by specifying the "Find" field as "Foo(([\sa-zA-Z_$]*))" and the
"Replace" field as "Bar$1". Note that there are differences in various regex engines - the
regex engine used by the converter is .NET System.Text.RegularExpressions.Regex.
Type & Member Replacements
Java to C++ Converter allows you to specify your own
custom type and member replacements in the converted code. This can be useful
for cases where you wish to specify replacements for Java library member calls
of a specific type that are not handled by Java to C++ Converter.
For each external type, you can specify an optional type replacement and multiple member
replacements. For types, you can specify template/generic types, which may include '?' as
a wildcard type. A wildcard in the replacement type must have a matching wildcard in the
same position in the original type.
e.g., the following will replace all references to type 'Foo' having one 'int' type parameter
with 'Bar', having no type parameters:
original type: Foo<int>
replacement type: Bar
e.g., the following will replace all references to type 'Foo' having one type parameter of any
type with 'Bar', having the same type parameter:
original type: Foo<?>
replacement type: Bar<?>
For each member replacement, you specify the original member name, whether the member is static
or not, and whether the member is a method or a field. You also specify the number of arguments
you expect.
For the replacement member, you specify whether the replacement is static or not, and whether
the replacement is a method or a field. You also specify the new list of arguments and can
add literal arguments. For replacement of static methods with instance members, you also
specify the argument position which corresponds to the object instance for the new instance
member. For replacement of instance members with static members, you specify the new class
name used to call the static member (for static methods, you also specify the position in
the argument list to insert the previous instance qualifier, using the string "instance"
(quotes not included) at the appropriate position in the "new argument list" field).
For example, if you want to replace all instance calls to the 'Foo' type method 'Bar'
where you want the instance qualifier to be the new first argument, you would specify
"instance, a1" (quotes not included) for the "new argument list" field, assuming that there
was one argument in the original method calls.
Diagnostic Options
These options are intended to provide information to
Tangible Software Solutions if a conversion is taking longer than expected.
'Record processing by file' instructs the converter to make a record of the files
processed and the time taken for each process. 'Record the last 100 lines of code
parsed before cancelling conversion' instructs the converter to make a record of the
most recent lines parsed before you cancelled the conversion.
File Encoding Options
The converter detects input file encoding from the byte order
mark (BOM), but if the BOM is missing the converter assumes by default that the file encoding
is UTF-8. You can use this option to specify a different default encoding to use in the absence
of a BOM. Output is written in the same encoding as the encoding detected for the original file,
or your default encoding option if the original coding was not detected via the BOM.
For UTF-8, you can choose whether or not to include the BOM for the output - this is normally
used in Windows environments.
Naming Conventions
By default, the converter does not change naming conventions,
but you can select these options to cause the converter to modify names to conform
to these common C++ conventions.
Omit Types from Conversion
Any type entered here will be omitted from most
conversion logic. You would normally enter library type names here to prevent the
default conversion of objects of those types.
Miscellaneous Options
- Renaming tag for code element conflicts: Java to C++ Converter
must occasionally rename class members to avoid conflicts. You can choose your own
renaming tag and whether to place it at the beginning or end of the original name.
- Renaming tag for C++ keyword conflicts: Java to C++ Converter
must occasionally rename identifiers that are keywords in C++. You can choose your own
renaming tag and whether to place it at the beginning or end of the original name when
this is necessary.
- String & character conversion: The Java types String and
char convert to the C++ types std::wstring and wchar_t by default,
but you also have the option of converting to std::string and char,
std::u16string and char16_t, or std::u32string and char32_t.
- Conversion of method 'throws' clause: The Java throws
clause is removed by default, but you can also choose to convert to noexcept(false)
or to the deprecated C++ throw clause.
- Raw pointer memory management:
- Add destructor 'delete' statements for class instance fields:
By default, the converter adds delete statements to the class destructor
(either the converted 'close' method or a new method) for all class instance fields
using pointers (unless you have chosen to convert to 'smart' pointers).
If you want to handle this differently, then unselect this option.
- Add 'delete' statements for local variables:
By default, the converter adds delete statements for local pointer variables
that satisfy certain conditions (unless you have chosen to convert to 'smart' pointers).
The conditions are that the variable must not be assigned to a field, parameter, or a
pointer in an outer scope and the variable must not be passed to a method or
constructor - these cases must be handled manually.
If you want to handle all local pointer deallocation manually, then unselect this option.
- Field initializations in constructors: By default, the
converter moves final instance field initializations within constructors the constructor
init list. You can also choose to move all instance field initializations within constructors to the
init list or to leave all initializations within the constructor body.
- Copy non-code files in folder conversions: By default,
the converter does not copy non-code files in folder conversions. If you select this
option, all non-code files are copied to the target folder.
- Convert arrays to std::vector: By default,
Java to C++ Converter converts arrays to std::vector, but if you unselect
this option they are converted to C++ arrays.
- Use spaces in nested template closing angle brackets:
Check this preference if you are targeting C++ compilers which require spaces in nested
template closing angle brackets (e.g., A<B<C> > instead of A<B<C>>).
- Preserve names for pure virtual parameters: By default,
Java to C++ Converter includes the parameter names for pure virtual method parameters.
Uncheck this if you don't want the original name included (this is optional in C++).
- Convert Java functional interfaces to C++ function pointers:
By default, Java to C++ Converter converts functional interfaces to C++ function pointers
if the functional interface has no default, static, or Object overriding methods.
- Add helper classes for unconverted exceptions:
By default, the converter adds helper classes which inherit from std::exception
for each unconverted exception.
- Add 'using namespace std' to .cpp files: By default,
the converter uses the full std qualifier for std members and types.
If you select this option, the converter will remove the std qualifier
and add a using namespace std to the top of the file for .cpp files.
- Assume 'import java.util.*' for snippet conversions:
By default, the converter assumes that the original Java code has an 'import java.util.*'
statement for code snippet conversions, unless you uncheck this option.
- Assume 'import java.util.concurrent*' for snippet conversions:
By default, the converter assumes that the original Java code has an 'import java.util.concurrent.*'
statement for code snippet conversions, unless you uncheck this option.
- Assume 'import java.util.function.*' for snippet conversions:
By default, the converter assumes that the original Java code has an 'import java.util.function.*'
statement for code snippet conversions, unless you uncheck this option.
- Assume 'import java.util.stream.*' for snippet conversions:
By default, the converter assumes that the original Java code has an 'import java.util.stream.*'
statement for code snippet conversions, unless you uncheck this option.
- Convert fundamental type parameters to const references: For
C++ output, the converter converts fundamental type parameters to
by value parameters by default.
- Convert string parameters to const references: The
converter converts string parameters to const references by default.
- Convert digit separators to C++14 digit separators:
Check this option if you want Java digit separators (underscores in numeric literals)
converted to C++14 digit separators (otherwise Java digit separators are simply removed).
- Convert java.io.Closeable.close methods to destructors:
Check this option if you want Java close methods for classes implementing the
java.io.Closeable interface to convert to C++ destructors.
- Generate a C++ 'main' function to call the original 'main' method, if found:
By default, if the converter finds a Java main method, then a C++ main function
is generated which calls the converted original main class method.
- Omit conversion of 'import' statements starting with:
By default, the converter omits the conversion of 'import' statements for package names
beginning with 'java' and 'javax', but you can add to these or remove them.
Copyright © Tangible Software Solutions, Inc.